/**
 * Created by ercha on 2016/1/1.
 */

$(document).ready(function(){

    $('#updateForm').validate({
        rules:{
            password: {
                required: true,
                rangelength: [3,22]
            },
            confirmPassword: {
                required: true,
                equalTo: "#password"
            }
        },
        message: {
            confirmPassword: {
                equalTo: "两次输入的密码不一致"
            }
        },
        //error 是一个 <label> 块，label 的内容是错误信息
        errorPlacement: errorPlacement,
        success: success,
        submitHandler: function(form){
            waitMessage();
            $.ajax({
                url: path + "/admin/resetPassword",
                type: "post",
                dataType: "json",
                data: {
                    id: $("#id").val(),
                    password: $("#password").val()
                },
                success: function(data){
                    if(data.success){
                        successMessage("操作成功！");
                        window.location = (path + "/admin/list");
                    } else{
                        errorMessage(data.msg);
                    }
                }
            });
        }
    });
});

